In Java, exceptions can be broadly categorized into two types: Built-in Exceptions and User-Defined Exceptions.
Built-in Exceptions
Built-in exceptions are the exceptions that are available in Java libraries. These exceptions are suitable to explain certain error situations. Built-in exceptions can be further divided into two categories:
Checked Exceptions: Checked exceptions are called compile-time exceptions because these exceptions are checked at compile-time by the compiler. The compiler ensures whether the programmer handles the exception or not.
Unchecked Exceptions: Unchecked exceptions are runtime exceptions. The compiler does not check these exceptions at compile time.
Here are some examples of built-in exceptions:
✦ ArithmeticException: Thrown when an exceptional condition has occurred in an arithmetic operation.
✦ ArrayIndexOutOfBoundsException: Thrown to indicate that an array has been accessed with an illegal index.
✦ ClassNotFoundException: This Exception is raised when we try to access a class whose definition is not found.
✦ FileNotFoundException: This Exception is raised when a file is not accessible or does not open.
✦ IOException: It is thrown when an input-output operation failed or interrupted.
✦ NullPointerException: This exception is raised when referring to the members of a null object.
✦ NumberFormatException: This exception is raised when a method could not convert a string into a numeric format.
✦ RuntimeException: This represents an exception that occurs during runtime.
✦ StringIndexOutOfBoundsException: It is thrown by String class methods to indicate that an index is either negative or greater than the size of the string.
✦ IllegalArgumentException: This exception will throw the error or error statement when the method receives an argument which is not accurately fit to the given relation or condition.
✦ IllegalStateException: This exception will throw an error or error message when the method is not accessed for the particular operation in the application.
User-Defined Exceptions
Java also allows users to define their own exceptions. These are custom exceptions that users can create for their specific program requirements.
Remember, proper exception handling can improve a Java application’s robustness and performance capabilities. It’s an essential part of writing a reliable and fault-tolerant Java program.
📌TAGS
★Class
★ Method
★ Object
★ java
★ oops
★ Interface
★ Exception handling